<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/myStrategyComment.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<link rel="stylesheet" href="../js/plugins/jquery-confirm/css/jquery-confirm.css">
		<script src="../js/plugins/jquery-confirm/jquery-confirm.js"></script>
		<link rel="stylesheet" href="/js/plugins/distSide/css/demo.css">-->
		<link rel="stylesheet" href="/js/plugins/distSide/css/normalize.css">
		<link rel="stylesheet" href="/js/plugins/distSide/dist/canvi.css">
		<script src="/js/plugins/distSide/dist/canvi.js"></script>
		<script src="/js/plugins/jquery-form/jquery.form.js"></script>


		<script src="/js/common.js"></script>
		<script>
            //禁用数组参数自动带[]
            $.ajaxSettings.traditional = true;
			$(function () {
				var params = getParams();
				if(!params.strategyId) {
					return;
				}

                //图片所在的div
				var rect;

                $(".rect").click(function () {
                    rect = $(this);
                    if(rect.html().indexOf("img")>-1){
                        //是否删除
                        $.confirm({
                            title:false,
                            content:'是否需要删除?',
                            buttons: {
                                confirm: {
                                    text: '删除',
                                    btnClass: 'btn-blue',
                                    action: function () {
                                        rect.html('<span>上传</span>');
                                    }
                                },
                                cancel: {
                                    text: '取消'
                                }
                            }
                        })
                    }else{
                        //打开选择图片窗口
                        $('[name="image"]').click();
                    }
                })

				//上传图片
				$('[name="image"]').change(function () {
                    var img = $('[name="image"]').val();

					if(img){
						$.ajax({
							url: '/images',
							type: 'POST',
							data: new FormData($('#imgForm')[0]),
							processData: false,
							contentType: false,
							success: function (data) {
								if (data.status == 1) {
									rect.html("<img width='100%' src='"+data.url+"'/>")
								} else {
									$(document).dialog({
										content: data.msg
									});
								}
							}
						});
					}



				});

				//评星星等级
				$(".star i").click(function () {
					var num = $(this).data('num');
					var children = $(".star").children("i");
					$(".star i").removeClass("fa-star").addClass("fa-star-o");
					for(var i=0;i<num;i++){
						$(children[i]).addClass("fa-star");
						$(children[i]).removeClass("fa-star-o");
					}
				})



				//获取标签用于页面渲染
				$.get("/tag",function (data) {
                    $(".tag").renderValues({list:data})
                })



                //提交表单
                $("#submitBtn").click(function () {
                    //获取评论的相关信息
                    //星星
                    var starNum = $(".fa-star").length;
                    //评价内容
                    var content = $("[name=content]").val();
                    //图片
                    var imgs = $(".imgs img");
                    var imgUrls = "";
                    for(var i=0;i<imgs.length;i++){
                        imgUrls += $(imgs[i]).attr('src')+";";
                    }

					imgUrls = imgUrls.substr(0, imgUrls.length - 1);

                    //系统推荐标签
                    var arr = [];
                    var tags = $(".tag .active input");
                    for(var i =0;i<tags.length;i++){
                        arr[i]=$(tags[i]).val()
                    }





					//系统推荐标签
                    /*var tags = $("label.active").children();
                    for(var i=0;i<tags.length;i++){
                        var tagName = $(tags[i]).val();
                        comment["tags["+i+"].name"] = tagName;
                    }*/

					var comment = '';



                    //自定义标签
                    var myTags = $("[name=myTags]").val().split(" ");
                    if(myTags){
                        for(var j=0;j<myTags.length;j++) {
                            if (myTags[j].trim()!="") {
                            	tags.push(myTags[i])

                                //comment["tags[" + i + "].name"] = myTags[j].trim();
                                i++;
                            }
                        }
                    }

					comment = {
						starNum : starNum,
						content : content,
						imgUrls : imgUrls,
						"strategy.id" : params.strategyId,
						tagIds:arr,
						myTags:myTags
					};

					// 提交评论
                    var strategyId = params.strategyId
					var login = sessionStorage.getItem('user')
					var loginer =  JSON.parse(login)
					$.post('/strategies/comments',comment,function (data) {


						var strategyIdNow =data.data;
						if(data.success){
                           window.location.href="/strategyComment.html?id="+strategyIdNow;
                        }else {
                            $(document).dialog({
                                content: data.msg
                            });
                        }
                    })
                })


				// --------------------@显示用户-------------------
				var num = 0;
                var text = '';
				$('#mainContent').keyup(function () {
                    text = $(this).val();
                    var length = text.length - 1;
                    var char = text.charAt(length);
                    if (char == '@') {
                        num ++;
                        if(num % 2 == 0){
                            var html = '';
                            $.get('/users/getAllUsers', function (data) {

                                $(data.list).each(function (index, ele) {
                                    html += '<li><a role="button" class="canvi-navigation__item everyMenu">\n' +
                                        '<span class="canvi-navigation__icon-wrapper" style="background: #00adff;">\n' +
                                        '<span class="canvi-navigation__icon icon-iconmonstr-code-2">\n' +
                                        '</span></span><span class="canvi-navigation__text nickSpan">'+ele.nickName+'</span>\n' +
                                        '</a></li>'
                                })
                                $('#ulSided').html(html);

                                // $('#topSide').renderValues(data);
                                $('#leftSide').click();
                                $('.everyMenu').click(function () {
                                    var nickSpan = $(this).find('.nickSpan');
                                    var name = $(nickSpan).html();
                                    $('#mainContent').val(text + name + ' ');
                                    $('.closeBtn').click();
                                    $('#mainContent').focus();
                                })
                            })
						}
                    }
                })


                $('#liSide').on('click', $('.everyMenu'), function () {
                })


				// ---------------------end----------------------------

			})
		</script>


	</head>

	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col">
				<a href="javascript:window.history.go(-1)">
					<span><i class="fa fa-chevron-left"></i></span>
				</a>

			</div>
			<div class="col">
				<span>点评</span>
			</div>
			<div class="col"></div>
		</div>
	</div>

	<div class="comment">
		<div class="container star">
			<p>你对该旅游地的评价</p>
			<i class="fa fa-star-o fa-lg" data-num="1"></i>
			<i class="fa fa-star-o fa-lg" data-num="2"></i>
			<i class="fa fa-star-o fa-lg" data-num="3"></i>
			<i class="fa fa-star-o fa-lg" data-num="4"></i>
			<i class="fa fa-star-o fa-lg" data-num="5"></i>
		</div>
		<hr />
		<div class="container tag" >
			<p>请为该旅游地选择合适的标签（大家都在评）</p>
			<div class="btn-group-toggle tagName" data-toggle="buttons" render-loop="list">
					<label class="btn btn-outline-danger ">
						<input id="che" type="checkbox" autocomplete="off" render-value="list.id">
						<p render-html="list.name"></p>
					</label>

			</div>

			<p>添加你自己的标签</p>
			<input name="myTags" class="form-control"  placeholder="请使用空格隔开标签，每个标签不超8个字"   />

			<p>更多评价内容</p>
			<textarea id="mainContent" name="content" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>
		</div>
		<div class="container imgs ">
			<p>上传图片</p>

			<div class="row">
				<form id="imgForm" method="post" enctype="multipart/form-data" >
					<input type="file" id="uploadInput" style="display: none" name="image"/>
				</form>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
			</div>
		</div>

	</div>


	<div class="operation">
		<button class="btn" onclick="window.history.go(-1)">放弃评价</button>
		<button class="btn" id="submitBtn">提交评价</button>
	</div>



	<!--侧边栏-->
	<aside class="myCanvasNav canvi-navbar" id="topSide">
		<div class="canvi-user-info">
			<div class="canvi-user-info__image">
				<img src="/js/plugins/distSide/pine-logo.jpg">
			</div>
			<div class="canvi-user-info__data">
					<span class="canvi-user-info__title">请选择您要@的好友</span>
				<a href="#" class="canvi-user-info__meta">View site</a>
				<div class="canvi-user-info__close closeBtn" onClick="t.close();"></div>
			</div>
		</div>

		<ul class="canvi-navigation" id="ulSided">
			<li>
				<a role="button" class="canvi-navigation__item everyMenu">
					<span class="canvi-navigation__icon-wrapper" style="background: #00adff;">
						<span class="canvi-navigation__icon icon-iconmonstr-code-2">
						</span>
					</span>
					<span class="canvi-navigation__text nickSpan"></span>
				</a>
			</li>
		</ul>
	</aside>




	<main class="js-canvi-content canvi-content" style="display: none">
		<div class="container">
			<div class="demo center">
				<button class="js-canvi-open-button--left btn" id="leftSide">打开左侧侧边栏菜单</button>
			</div>
		</div>
		<div style="height:400px;"></div>
	</main>

	<script>
        var t = new Canvi({
            content: ".js-canvi-content",
            isDebug: !1,
            navbar: ".myCanvasNav",
            openButton: ".js-canvi-open-button--left",
            position: "left",
            pushContent: !1,
            speed: "0.2s",
            width: "100vw",
            responsiveWidths: [{
                breakpoint: "600px",
                width: "280px"
            }, {
                breakpoint: "1280px",
                width: "320px"
            }, {
                breakpoint: "1600px",
                width: "380px"
            }]
        })
	</script>
	<script type="text/javascript">
        var canviRight = new Canvi({
            content: '.js-canvi-content',
            navbar: '.js-canvi-navbar--right',
            openButton: '.js-canvi-open-button--right',
            position: "right"
        });
	</script>



	</body>


</html>